package com.shzu.jwc.ty.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shzu.jwc.ty.bean.SelectProblem;
import com.shzu.jwc.ty.bean.SelectProblemExample;
import com.shzu.jwc.ty.dao.SelectProblemMapper;

@Service
public class SelectProblemservice {

	@Autowired
	SelectProblemMapper selectProblemMapper;

	public Integer insertselect(SelectProblem selectproble)
	{
		SelectProblemExample example=new SelectProblemExample();
		SelectProblemExample.Criteria criteria=example.createCriteria();
		criteria.andSelectProblemStatueEqualTo(selectproble.getSelectProblemStatue());
		criteria.andSelectProblemTitleEqualTo(selectproble.getSelectProblemTitle());
		if(selectProblemMapper.countByExample(example)>0)
			return 1;
		else
			return selectProblemMapper.insert(selectproble);
	}
	
	
	public List<SelectProblem> getselectproblem(Integer statue)
	{
		SelectProblemExample example=new SelectProblemExample();
		SelectProblemExample.Criteria criteria=example.createCriteria();
		criteria.andSelectProblemStatueEqualTo(statue);
		return selectProblemMapper.selectByExample(example);
	}
	
	public List<SelectProblem> getsearchselectproblem(Integer statue,Integer problemClassId)
	{
		SelectProblemExample example=new SelectProblemExample();
		SelectProblemExample.Criteria criteria=example.createCriteria();
		criteria.andSelectProblemStatueEqualTo(statue);
		criteria.andProblemClassIdEqualTo(problemClassId);
		return selectProblemMapper.selectByExample(example);
	}
	
	public Integer deleteselect(Integer selectProblemId)
	{
		return selectProblemMapper.deleteByPrimaryKey(selectProblemId);
	}
	
	public Integer updateselect(Integer id,String column,String value)
	{
		SelectProblem selectProblem=selectProblemMapper.selectByPrimaryKey(id);
		if(column.equals("selectProblemTitle"))
			selectProblem.setSelectProblemTitle(value);
		if(column.equals("selectProblemOption1"))
			selectProblem.setSelectProblemOption1(value);
		if(column.equals("selectProblemOption2"))
			selectProblem.setSelectProblemOption2(value);
		if(column.equals("selectProblemOption3"))
			selectProblem.setSelectProblemOption3(value);
		if(column.equals("selectProblemOption4"))
			selectProblem.setSelectProblemOption4(value);
		if(column.equals("selectProblemRightoption"))
			selectProblem.setSelectProblemRightoption(value);
		if(column.equals("problemClassId"))
			selectProblem.setProblemClassId(Integer.parseInt(value));
		return selectProblemMapper.updateByPrimaryKey(selectProblem);
		
	}
}
